package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.SmsHomeNewProductApi;
import com.mail.model.db.SmsHomeNewProduct;
import com.mail.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsHomeNewProductService {

    @DubboReference
    private SmsHomeNewProductApi smsHomeNewProductApi;

    public void addNewProduct(List<SmsHomeNewProduct> newProducts) {
        for (SmsHomeNewProduct newProduct : newProducts) {
            smsHomeNewProductApi.save(newProduct);
        }
    }

    public void deleteBrand(List<Long> ids) {
        smsHomeNewProductApi.deleteNewProduc(ids);
    }

    public PageResult getNewProducByPage(Long pageNum, Long pageSize, String productName, Integer recommendStatus) {
        Page<SmsHomeNewProduct> page = smsHomeNewProductApi.getNewProducByPage(pageNum,pageSize,productName,recommendStatus);
        return new PageResult(Long.parseLong(String.valueOf(page.getCurrent())), Long.parseLong(String.valueOf(page.getSize())), Long.parseLong(String.valueOf(page.getTotal())), page.getRecords());    }

    public void updateNewProduct(List<Long> ids, Integer recommendStatus) {
        for (Long id : ids) {
            smsHomeNewProductApi.updateNewProduct(id,recommendStatus);
        }
    }

    public void updatesortNewProduct(Long id, Integer sort) {
        smsHomeNewProductApi.updatesortNewProduct(id,sort);
    }
}
